package com.rdtravel.web;

import com.rdtravel.entities.Customer;

import javax.validation.constraints.AssertTrue;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.BeanUtils;

class CustomerCreateForm  extends Customer {
	private static final long serialVersionUID = 1L;
	@NotBlank
	private String confirmPassword;

	public String getConfirmPassword() {
		return confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	@Override
	public void setPassword(String password) {
		super.setPassword(password);
	}
	
	@AssertTrue(message="{passwordAndConfirmPasswordShouldMatch}")
	public boolean isConfirmPasswordTheSameAsPassword() {
		if (getPassword()==null || getConfirmPassword() == null) {
			return true;
		}
		return  getPassword().equals(getConfirmPassword());
	}
	
	public Customer toCustomer() {
		Customer customer=new Customer();
		BeanUtils.copyProperties(this, customer);
		return customer;
	}
	
}
